package com.tsvetanv.data.binding.nested.collections.map;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.tsvetanv.data.binding.model.nested.NestedMapStringCommandBean;

import junit.framework.TestCase;

public class NestedMapStringBindTest extends TestCase {
	private NestedMapStringCommandBean bean;
	private ServletRequestDataBinder binder;
	private MockHttpServletRequest request;

	@Override
	protected void setUp() throws Exception {
		bean = new NestedMapStringCommandBean();
		binder = new ServletRequestDataBinder(bean, "beanName");
		request = new MockHttpServletRequest();
	}

	public void testNestedMapStringBind() {
		request.addParameter("friends['svircho']", "Ivan");
		request.addParameter("friends['dardorko']", "Petar");

		binder.bind(request);

		assertEquals("Ivan", bean.getFriends().get("svircho"));
		assertEquals("Petar", bean.getFriends().get("dardorko"));

	}
}
